﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

 
	public static class MD5Hepler
	{
		public static string GetMD5(this string source) {


			byte[] result = Encoding.Default.GetBytes(source);    //tbPass为输入密码的文本框
			MD5 md5 = new MD5CryptoServiceProvider();
			byte[] output = md5.ComputeHash(result);
		 return BitConverter.ToString(output).Replace("-", "").ToLower();  //tbMd5pass为输出加密文本的文本框

		}

		public static string GetBase64(Encoding encode, string source)
		{
			var bytes = encode.GetBytes(source);
			try
			{
				return Convert.ToBase64String(bytes) ;
			}
			catch
			{
				return source;
			} 
		}

		public static string GetBase64(this string source)
		{
			Encoding encode = Encoding.UTF8;

			return GetBase64(encode, source);
		}


	} 